import { IFeidaoAiBrowserComponent } from '@feidao/web/interfaces';

export default async function a005(fd: IFeidaoAiBrowserComponent, ...args: any[]) {
	console.log('one_check');
	const one_check = args[0].currentTarget as HTMLInputElement;
	const all_check = fd.data.node.querySelector('[data-feidao-id="all_check"]') as HTMLInputElement;
	const _id = one_check.getAttribute('_id');
	const staff_number = one_check.getAttribute('staff_number');
	!fd.data.select_staff && (fd.data.select_staff = []);
	if (one_check.checked) {
		fd.data.select_staff.push({ _id, staff_number });
		const all_cs = Array.from(fd.data.node.querySelectorAll('[data-feidao-id="one_check"]'));
		const f = all_cs.some((c: HTMLInputElement) => {
			return c.checked == false;
		});
		all_check.checked = !f;
	} else {
		all_check.checked = false;
		const curr_i = (() => {
			fd.data.select_staff.forEach((s: { _id: string }, i: number) => {
				if (_id == s._id) {
					return i;
				}
			});
		})();
		fd.data.select_staff.splice(curr_i, 1);
	}
}
